<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS3 动画</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: aqua;
    }

    .ani-1 {
      animation-name: move1;
      animation-duration: 2s;
    }

    @keyframes move1 {
      0% {
        transform: translateX(0);
      }

      100% {
        transform: translateX(300px);
      }
    }

    .ani-2 {
      background-color: antiquewhite;
      animation: move2 3s;
    }

    @keyframes move2 {
      0% {
        transform: translate(0, 0);
      }

      25% {
        transform: translate(300px, 0);
      }

      50% {
        transform: translate(300px, 100px);
      }

      75% {
        transform: translate(0, 100px);
      }

      100% {
        transform: translate(0, 0);
      }
    }

    .map {
      position: relative;
      width: 800px;
      height: 450px;
      background: url(img/map-800_450.png) no-repeat;
      margin: 20px auto;
      background-color: #eee;
    }

    .city {
      position: absolute;
      font-family: Arial, Helvetica, sans-serif;
      color: #c81623;
      font-weight: 700;
    }

    .beijing {
      top: 145px;
      left: 650px;
    }

    .washington {
      top: 168px;
      left: 196px;
    }

    .dot {
      width: 8px;
      height: 8px;
      background-color: #c81623;
      border-radius: 50%;
    }

    .city div[class^="wave"] {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 8px;
      height: 8px;
      box-shadow: 0 0 12px #ec3542;
      border-radius: 50%;
      animation: wave 1.2s infinite linear;
    }

    .city div.wave2 {
      animation-delay: .4s;
    }

    .city div.wave3 {
      animation-delay: .8s;
    }

    @keyframes wave {
      0% {}

      70% {
        width: 40px;
        height: 40px;
        opacity: 1;
      }

      100% {
        width: 70px;
        height: 70px;
        opacity: 0;
      }
    }

    .step {
      animation: step 4s steps(10) forwards;
    }

    .ad {
      overflow: hidden;
      font-size: 20px;
      width: 0;
      height: 30px;
      white-space: nowrap;
      animation: ad 4s steps(9) forwards;
    }

    @keyframes step {
      from {}

      to {
        width: 900px;
      }
    }

    @keyframes ad {
      from {}

      to {
        width: 180px;
      }
    }

    .bear {
      position: absolute;
      width: 200px;
      height: 100px;
      background: url(img/bear.png) no-repeat;
      background-color: #eee;
      /* 多个动画使用逗号并列 */
      animation: bear .8s steps(8) infinite, move 3s forwards;
    }

    @keyframes bear {
      from {
        background-position: 0 0;
      }

      to {
        background-position: -1600px 0;
      }
    }

    @keyframes move {
      from {
        left: 0;
      }

      to {
        left: 50%;
        transform: translate(-50%);
      }
    }
  </style>
</head>

<body>
  <h3>一. 动画的基本使用</h3>
  <p>制作动画分两步: </p>
  <ol>
    <li>定义动画: 定义关键帧名称和变化方式</li>
    <li>调用动画: 使用名称和持续时间</li>
  </ol>
  <div style="background: #eee; width: 180px;">
    <code>
    @keyframes 动画名称 { <br>
    &nbsp;&nbsp;0% {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;...<br>
    &nbsp;&nbsp;}<br>
    &nbsp;&nbsp;100% {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;...<br>
    &nbsp;&nbsp;}<br>
    }
  </code>
  </div>

  <p>动画序列: </p>
  <ol>
    <li>0% / from 是动画开始, 100% / to 是动画完成。这样的规则就是动画序列</li>
    <li>可以任意多次的改变任意多的样式</li>
    <li>利用百分比来规定变化发生的事件</li>
  </ol>

  <h4>示例</h4>
  <div class="box ani-1"></div>
  <div class="box ani-2"></div>

  <h3>二. 动画的常用属性</h3>
  <code>
    animation: name duration timing-function delay iteration-count direction fill-mode; <br>
      动画: 名称 持续时间 速度曲线 延迟开始时间 播放次数 是否在下一周期逆向播放(normal 正常/alternate 逆向) 结束后的状态(forwards 保持/backwards 初始) <br>
      animation-play-state: paused; 暂停播放
  </code>
  <h4>案例: 热点图</h4>
  <div class="map">
    <div class="city beijing">
      <div class="dot"></div>
      <div class="wave1"></div>
      <div class="wave2"></div>
      <div class="wave3"></div>
    </div>
    <div class="city washington">
      <div class="dot"></div>
      <div class="wave1"></div>
      <div class="wave2"></div>
      <div class="wave3"></div>
    </div>
  </div>
  <h4>速度曲线细节: steps() 步长,指定时间函数中的间隔数量</h4>
  <div class="step box"></div>
  <div class="ad">速度曲线的步长应用</div>
  <h4>案例: 关键帧动画</h4>
  <div class="bear"></div>
</body>

</html>